//
//  UIBarButton.swift
//  WymanWeibo
//
//  Created by wyman on 16/4/12.
//  Copyright © 2016年 wyman. All rights reserved.
//

import UIKit

extension  UIBarButtonItem {

    //遍历构造函数
    convenience init(imageName: String, target: AnyObject?, action: Selector) {
        let button = UIButton()
        
        //设置按钮
        button.setImage(UIImage.init(named: imageName), forState: .Normal)
        button.setImage(UIImage.init(named: "\(imageName)_highlighted"), forState: .Highlighted)
        
        button.sizeToFit()
        
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        self.init(customView: button)
    }
    
    //使用类方法
    
    class func createBarButtonItem(imageName: String) -> UIBarButtonItem{
    let button = UIButton()
        
        button.setImage(UIImage.init(named: imageName), forState: .Normal)
        button.setImage(UIImage.init(named: "\(imageName)_highlighted"), forState: .Highlighted)
    
        button.sizeToFit()

        return UIBarButtonItem(customView: button)
    
    
    }
    
}
